﻿@model HZU.ZP.Domain.Model.NoticeView
@{
    switch (User.Claims.ToList()[2].Value)
    {
        case "Admin":
            Layout = "_AdminLayout";
            break;
        case "Company":
            Layout = "_CompanyLayout";
            break;
        case "Applicant":
            Layout = "_ApplicatLayout";
            break;
    }
}
<script>
    $(document).ready(function () {
        $("#save").click(function () {
            var $btn = $("#save").button('loading');
            var comment = new Object();
            comment.NoticeId = @Model.Notice.Id;
            comment.OwnerName = "@User.Identity.Name";
            comment.Content = $("#content").val();
            if (comment.Content == "" || $.trim(comment.Content) == "") {
                 alert("评论内容不能为空！");
                 $btn.button('reset');
                 return false;
            }
            $.ajax({
                type: "post",
                url: "/Comment/AddComment",
                contentType: "application/json",
                data: JSON.stringify(comment),
                dataType: "json",
                    success: function (message) {
                        if (message.returnCode == "001") {
                            alert("保存成功");
                            location.reload();
                        }
                }
            });
        });
        $(document).on("click","#cancel",function(){
            $(".unique").remove();
        });
        $(document).on("click", "#zan", function () {
            $('#zan').attr('disabled',"true");
            if ($(this).data("iszan") == "0") {
                $(this).css('color', 'red');
                $(this).data("iszan", "1");
                var total = $("#praisePoints").text();
                $("#praisePoints").text(parseInt(total)+1);
                $.ajax({
                type: "post",
                url: "/Zan/Add",
                data: "noticeId=@Model.Notice.Id&email=@User.Identity.Name",
                    success: function (message) {
                        if (message.returnCode == "001") {
                            $('#zan').data("id", message.zanId);
                            $('#zan').removeAttr("disabled");
                        }
                }
            });
            } else {
                $('#zan').attr('disabled',"true");
                $(this).css('color', '');
                $(this).data("iszan", "0");
                 var total = $("#praisePoints").text();
                $("#praisePoints").text(parseInt(total) - 1);
                $.ajax({
                type: "post",
                url: "/Zan/Delete",
                data: "zanId="+$('#zan').data("id"),
                    success: function (message) {
                         if (message.returnCode == "001") {
                             $('#zan').data("id", "");
                             $('#zan').removeAttr("disabled");
                        }
                }
            });
            }
        });
    });
</script>
<script type="text/javascript">
        $(function () {
            var isZan = @(Model.Zan!=null?"1":"0");
            if (isZan == "1") {
                $("#zan").css('color', 'red');
                $("#zan").data("iszan", "1");
            }
        });
        function replay(obj)
        {
            $(".unique").remove();
            $(obj).parent().after("<div class=\"unique\"><textarea id=\"comContent\" class=\"form-control\" style=\"height:80px\" placeholder=\"写下您的评论...\"></textarea><button id=\"addCom\" class=\"form-control\" style=\"background-color: #79CDCD;float:right;width:20%;\" data-loading-text=\"保存中...\" >保存</button><button id=\"cancel\" class=\"form-control\" style=\"float:right;width:20%;\">取消</button><br/></div>");
            $("#addCom").click(function () {
                var $btn = $("#addCom").button('loading');
            var comment = new Object();
                comment.NoticeId = @Model.Notice.Id;
                comment.CommentId = $(obj).attr("data-id");
                comment.OwnerName = "@User.Identity.Name";
                comment.TargetName = $(obj).attr("data-name");
                comment.Content = $("#comContent").val();
                 if (comment.Content == "" || $.trim(comment.Content) == "") {
                 alert("评论内容不能为空！");
                 $btn.button('reset');
                 return false;
            }
            $.ajax({
                type: "post",
                url: "/Comment/AddComment",
                contentType: "application/json",
                data: JSON.stringify(comment),
                dataType: "json",
                    success: function (message) {
                        if (message.returnCode == "001") {
                            alert("保存成功");
                            location.reload();
                        }
                }
            });
        });
        }
        function lookReplay(obj)
        {
            $(".unique").remove();
            $.ajax({
                type: "get",
                url: "/Comment/GetComComment",
                data: "commentId=" + $(obj).attr("data-id"),
                success: function (message) {
                    ////alert(message);
                    //$.each(message.comments, function (i, items) {

                    var strings = "<div class=\"unique\" style=\"margin-left:30px;background-color:#d9d6c3;\">";
                    $.each(message.comments, function (i, items) {
                        strings = strings + "<div class=\"form-group\"><strong>" + items.ownerName +
                            "&nbsp;&nbsp; " + items.createTime.replace("T"," ").substr(0,19) +
                            "</strong ><p>" + items.content + "</p>";
                    });
                    strings = strings + "</div>";
                    $(obj).parent().after(strings);
                }
            });
        }
        function getComment(i) {
            $.ajax({
                type: "get",
                url: "/Comment/GetNoticeComment",
                data: "noticeId=@Model.Notice.Id&pageIndex=" + i,
                success: function (message) {
                    ////alert(message);
                    //$.each(message.comments, function (i, items) {

                    var strings = "<div id=\"lockComment\"><div class=\"row clearfix\"><div class=\"col-md-12 column\">";
                    $.each(message.comments, function (i, items) {
                        strings = strings + "<div class=\"form-group\"><strong>" + items.ownerName + "&nbsp;&nbsp;" + items.createTime.replace("T", " ").substr(0, 19) +
                            "</strong><p>" + items.content + "</p><p><a href=\"javascript:;\" onclick=\"replay(this)\" data-id=\"" + items.id + "\" data-name=\"" + items.ownerName +
                            "\">回复</a>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"lookReplay(this)\"data-id="+items.id+">查看回复</a></p></div>";
                    });
                    strings = strings +"<div class=\"row clearfix\"><div class=\"col-md-12 column\"><div style=\"text-align: center;\"><ul class=\"pagination\">"
                    for (var j = message.pageIndex - 2 <= 0 ? 1 : message.pageIndex - 2; j < message.pageIndex; j++) {
                        strings = strings + "<li><a href=\"javascript:;\" onclick=\"getComment(" + j + ")\">" + j + "</a></li>";

                    }
                    strings = strings + "<li><a href=\"javascript:;\" style=\"background-color:LightGrey\">" + message.pageIndex + "</a></li>";
                    for (var j = message.pageIndex + 1; j <= message.total && j < message.pageIndex + 2; j++) {
                        strings = strings + "<li><a href=\"javascript:;\" onclick=\"getComment(" + j + ")\">" + j + "</a></li>";

                    }
                    strings = strings + "<li><a style=\"border :none;background-color:white\">&nbsp;&nbsp;&nbsp;&nbsp;共"+message.total+"页</a></li></ul></div></div></div></div></div></div>";
                    $("#lockComment").empty();
                    $("#lockComment").append(strings);
                }
            });
        }
</script>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h2>@Model.Notice.Title</h2>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            @Html.Raw(Model.Notice.Content)
        </div>
    </div>
    <br />
    <div class="row clearfix">
        <div class="col-md-12 column">
            <span style="font-size: 30px;float:right;">(<span id="praisePoints">@Model.Notice.PraisePoints</span>)</span>
            <button class="btn btn-default btn-link" style="float:right;">
                <span id="zan" class="glyphicon glyphicon-thumbs-up" style="font-size: 30px;float:right;" data-iszan="0" data-id="@(Model.Zan==null?"":Model.Zan.Id.Value.ToString())"></span>
            </button>

        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <em style="color:red;font-size:larger;">@((int)ViewData["Count"])</em> 条评论
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="form-group">
                <textarea id="content" class="form-control" style="height:80px" placeholder="写下您的评论..."></textarea>
            </div>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="form-group">
                <button id="save" class="form-control" style="background-color: #79CDCD;float:right;width:20%;" data-loading-text="保存中...">保存</button>
            </div>
        </div>
    </div>
    <div id="lockComment">
        <div class="row clearfix">
            <div class="col-md-12 column">
                @if (Model.Comments.Count() > 0)
                {
                    foreach (var com in Model.Comments)
                    {
                        <div class="form-group">
                            <strong>
                                @com.OwnerName&nbsp;&nbsp;@com.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                            </strong>
                            <p>
                                @com.Content
                            </p>
                            <p>
                                <a href="javascript:;" onclick="replay(this)" data-id="@com.Id" data-name="@com.OwnerName">回复</a>&nbsp;&nbsp;
                                <a href="javascript:;" onclick="lookReplay(this)" data-id="@com.Id">查看回复</a>
                            </p>
                        </div>
                    }
                    <div class="row clearfix">
                        <div class="col-md-12 column">
                            <div style="text-align: center;">
                                <ul class="pagination">
                                    @for (int i = (int)ViewData["PageIndex"] - 2 <= 0 ? 1 : (int)ViewData["PageIndex"] - 2; i < (int)ViewData["PageIndex"]; i++)
                                    {
                                        <li><a href="javascript:;" onclick="getComment(@i)">@i</a></li>
                                    }
                                    @if ((int)ViewData["PageIndex"] > 0)
                                    {
                                        <li><a href="javascript:;" style="background-color:LightGrey">@((int)ViewData["PageIndex"])</a></li>
                                    }
                                    @for (int i = (int)ViewData["PageIndex"] + 1; i <= (int)ViewData["PageCount"] && i < (int)ViewData["PageIndex"] + 2; i++)
                                    {
                                        <li><a href="javascript:;" onclick="getComment(@i)">@i</a></li>
                                    }
                                    <li><a style="border :none;background-color:white">&nbsp;&nbsp;&nbsp;&nbsp;共@((int)ViewData["PageCount"])页</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
</div>
